#include "Global.h"
#include "..\..\User\config.h"

u16 u16KnobBrightness;
u8 u8KnobBrightnessStep;

void Api_Pwm_KnobBrightness_Init(void)
{
	u16KnobBrightness = 6000;
}

void Api_Pwm_KnobLedOn(void)
{
	if(u16KnobBrightness > 3000)
		u16KnobBrightness = u16KnobBrightness - 60;
	else if(u16KnobBrightness > 1000)
		u16KnobBrightness = u16KnobBrightness - 250;
	else
		u8KnobBrightnessStep = 1;
	Drive_Pwm_SetPwmDuty(u16KnobBrightness);
}

void Api_Pwm_KnobLedOff(void)
{
	if(u16KnobBrightness < 3000)
		u16KnobBrightness = u16KnobBrightness + 250;
	else if(u16KnobBrightness < 6000)
		u16KnobBrightness = u16KnobBrightness + 60;
	else
		u8KnobBrightnessStep = 0;
	Drive_Pwm_SetPwmDuty(u16KnobBrightness);
}

#if(TEST_PWM)
void TestPwm(void)
{
	switch(u8KnobBrightnessStep)
	{
		case 0:
			Api_Pwm_KnobLedOn();
		break;
		
		case 1:
			Api_Pwm_KnobLedOff();
		break;
		
		default:
			break;
	}
}
#endif



//void f_App_KnobPwm_CircleOn(void)
//{
////        TMM1_PWM_1Perdod_1Duty_TMOB1(TMM_CLOCK_FCLK, 4800, 1, 0, 0);
//        TMM1_PWM_1Perdod_1Duty_TMOB1(TMM_CLOCK_FCLK, 4800, 2400, 0, 0);
//        u8KnobBrightnessStep = 0;
//}

//void f_App_KnobPwm_CircleOff(void)
//{
//        TMM1_PWM_1Perdod_1Duty_TMOB1(TMM_CLOCK_FCLK, 4800, 4800, 0, 0);
//        u8KnobBrightnessStep = 0;
//}

//void f_App_KnobPwm_add(void)
//{
////        if(u16KnobBrightness > 2400)
//        if(u16KnobBrightness > 3600)
//                u16KnobBrightness = u16KnobBrightness - 100;
////        else if(u16KnobBrightness > 0)
//        else if(u16KnobBrightness > 2400)
//                u16KnobBrightness = u16KnobBrightness - 200;
//        else
//                u8KnobBrightnessStep = 1;
//        TMM1_PWM_1Perdod_1Duty_TMOB1(TMM_CLOCK_FCLK, 4800, u16KnobBrightness, 0, 0);
//}

//void f_App_KnobPwm_dec(void)
//{
//        if(u16KnobBrightness < 2400)
//                u16KnobBrightness = u16KnobBrightness + 200;
//        else if(u16KnobBrightness < 4800)
//                u16KnobBrightness = u16KnobBrightness + 100;
//        else
//                u8KnobBrightnessStep = 0;
//        TMM1_PWM_1Perdod_1Duty_TMOB1(TMM_CLOCK_FCLK, 4800, u16KnobBrightness, 0, 0);
//}
